<?php
Yii::import('application.models._base.BaseAuctionLimit');

class AuctionLimit extends BaseAuctionLimit
{
    const EXPIRE_TIME=2592000;
    
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function relations()
    {
        return array(
            'Customer' => array(
                self::BELONGS_TO,
                'Customer',
                'winner_id'
            )
        );
    }
    
    public function searchWinLimit($type,$winnerId){
        $criteria = new CDbCriteria;
        $criteria->join="LEFT JOIN auction_parame as t2 ON t.auction_id=t2.auction_id";
        $criteria->addCondition("t.winner_id=".$winnerId);
        $criteria->compare("t2.parame_name", "type");
        $criteria->compare("t2.parame_value", $type);
        $criteria->order="t.winner_time DESC";
        $criteria->addCondition("t.winner_time+".self::EXPIRE_TIME.">=".time());
        $criteria->addNotInCondition("t.limit_type", [
            "BUY_IT_NOW"
        ]);
        return  $a=new CActiveDataProvider($this, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>15, //当前页数显示记录条数
            ),
        ));
    }
    
}

